local ranshang = fk.CreateSkill {

  name = "joy__ranshang",

  tags = { Skill.Compulsory, },

}



ranshang:addEffect(fk.Damaged, {
  name = "joy__ranshang",
  anim_type = "negative",
  frequency = Skill.Compulsory,
  events = {fk.Damaged, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(ranshang.name) then
      if event == fk.Damaged then
        return data.damageType == fk.FireDamage
      else
        return player.phase == Player.Finish and player:getMark("@wutugu_ran") > 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      room:addPlayerMark(player, "@wutugu_ran", data.damage)
    else
      room:loseHp(player, player:getMark("@wutugu_ran"), ranshang.name)
      if not player.dead and player:getMark("@wutugu_ran") >= 2 then
        room:changeMaxHp(player, -2)
        if not player.dead then
          player:drawCards(player:getMark("@wutugu_ran"), ranshang.name)
        end
      end
    end
  end,
})
ranshang:addEffect(fk.EventPhaseStart, {
  name = "joy__ranshang",
  anim_type = "negative",
  frequency = Skill.Compulsory,
  events = {fk.Damaged, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(ranshang.name) then
      if event == fk.Damaged then
        return data.damageType == fk.FireDamage
      else
        return player.phase == Player.Finish and player:getMark("@wutugu_ran") > 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      room:addPlayerMark(player, "@wutugu_ran", data.damage)
    else
      room:loseHp(player, player:getMark("@wutugu_ran"), ranshang.name)
      if not player.dead and player:getMark("@wutugu_ran") >= 2 then
        room:changeMaxHp(player, -2)
        if not player.dead then
          player:drawCards(player:getMark("@wutugu_ran"), ranshang.name)
        end
      end
    end
  end,
})

return ranshang